﻿'Copyright (C) 2010  Thomas Huebner
'
'This program is free software
'
'you can redistribute it and/or modify it under the terms 
'of the GNU General Public License as published by the 
'Free Software Foundation either version 2 of the License, 
'or (at your option) any later version.
'
'This program is distributed in the hope that it will be 
'useful, but WITHOUT ANY WARRANTY without even the implied 
'warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. 
'See the GNU General Public License for more details.
'
'You should have received a copy of the GNU General Public License 
'along with this program; if not, write to the 
'Free Software Foundation, Inc., 59 Temple Place, Suite 330, 
'Boston, MA 02111-1307, USA. 


Imports System.Xml.Serialization
Imports System.IO
Imports System.Text
Imports System.ComponentModel


Public Class LF_SuggestionListConverter
    '''
    ''' <summary>Read a String to LF_InitiativeList object </summary>
    ''' <param name="text" >XML Source as string</param>
    ''' <returns>LF_InitiativeList object</returns>
    '''
    Public Shared Function ReadSuggestionList(ByVal text As String) As LF_SuggestionList
        Dim xs As New XmlSerializer(GetType(LF_SuggestionList))
        Dim tr As TextReader = New StringReader(text)
        Return DirectCast(xs.Deserialize(tr), LF_SuggestionList)
    End Function

    '''
    ''' <summary>Write an LF_InitiativeList object to XML string</summary>
    ''' <param name="oLF_SuggestionList" >LF_InitiativeList object</param>
    ''' <returns>XML Source as string</returns>
    '''
    Public Shared Function WriteSuggestionList(ByVal oLF_SuggestionList As LF_SuggestionList) As String
        Dim xs As New XmlSerializer(GetType(LF_SuggestionList))
        Dim sb As New StringBuilder()
        Dim tw As TextWriter = New StringWriter(sb)
        xs.Serialize(tw, oLF_SuggestionList)
        Return tw.ToString
    End Function

End Class


<XmlRoot("suggestion_list")> _
Public Class LF_SuggestionList

    <XmlNamespaceDeclarations()> _
        Public namespaces As XmlSerializerNamespaces

    <XmlAttribute("version")> _
        Public version As String

    <XmlElement("suggestion")> _
        Public items As LF_Suggestion()

End Class


''' <summary>
''' This class reflect a single Suggestion
''' </summary>
''' <remarks></remarks>
Public Class LF_Suggestion

    <EditorBrowsable(EditorBrowsableState.Never)> _
    <XmlElement("id")> _
        Public _ID As String

    ''' <summary>
    ''' Id of the suggestion
    ''' </summary>
    ''' <value></value>
    ''' <returns>Integer</returns>
    ''' <remarks></remarks>
    <XmlIgnore()> _
    Public ReadOnly Property ID() As Integer
        Get
            If Not String.IsNullOrEmpty(Me._ID) Then
                Return CInt(Me._ID)
            Else
                Return 0
            End If
        End Get
    End Property


    <EditorBrowsable(EditorBrowsableState.Never)> _
    <XmlElement("initiative_id")> _
        Public _InitiativeID As String

    ''' <summary>
    ''' Id of the initiative.
    ''' </summary>
    ''' <value></value>
    ''' <returns>Integer</returns>
    ''' <remarks></remarks>
    <XmlIgnore()> _
    Public ReadOnly Property InitiativeID() As Integer
        Get
            If Not String.IsNullOrEmpty(Me._InitiativeID) Then
                Return CInt(Me._InitiativeID)
            Else
                Return 0
            End If
        End Get
    End Property


    <EditorBrowsable(EditorBrowsableState.Never)> _
    <XmlElement("name")> _
        Public _Name As String

    ''' <summary>
    ''' Title of the suggestion.
    ''' </summary>
    ''' <value></value>
    ''' <returns>Integer</returns>
    ''' <remarks></remarks>
    <XmlIgnore()> _
    Public ReadOnly Property Name() As String
        Get
            If Not String.IsNullOrEmpty(Me._Name) Then
                Return Me._Name.Trim
            Else
                Return String.Empty
            End If
        End Get
    End Property


    <EditorBrowsable(EditorBrowsableState.Never)> _
    <XmlElement("description")> _
        Public _Description As String

    ''' <summary>
    ''' Description of the suggestion.
    ''' </summary>
    ''' <value></value>
    ''' <returns>Integer</returns>
    ''' <remarks></remarks>
    <XmlIgnore()> _
    Public ReadOnly Property Description() As String
        Get
            If Not String.IsNullOrEmpty(Me._Description) Then
                Return Me._Description
            Else
                Return String.Empty
            End If
        End Get
    End Property


    <EditorBrowsable(EditorBrowsableState.Never)> _
    <XmlElement("minus2_unfulfilled_count")> _
        Public _Minus2UnfulfilledCount As String

    ''' <summary>
    ''' </summary>
    ''' <value></value>
    ''' <returns>Integer</returns>
    ''' <remarks></remarks>
    <XmlIgnore()> _
    Public ReadOnly Property Minus2UnfulfilledCount() As Integer
        Get
            If Not String.IsNullOrEmpty(Me._Minus2UnfulfilledCount) Then
                Return CInt(Me._Minus2UnfulfilledCount)
            Else
                Return 0
            End If
        End Get
    End Property


    <EditorBrowsable(EditorBrowsableState.Never)> _
    <XmlElement("minus2_fulfilled_count")> _
        Public _Minus2FulfilledCount As String

    ''' <summary>
    ''' </summary>
    ''' <value></value>
    ''' <returns>Integer</returns>
    ''' <remarks></remarks>
    <XmlIgnore()> _
    Public ReadOnly Property Minus2FulfilledCount() As Integer
        Get
            If Not String.IsNullOrEmpty(Me._Minus2FulfilledCount) Then
                Return CInt(Me._Minus2FulfilledCount)
            Else
                Return 0
            End If
        End Get
    End Property


    <EditorBrowsable(EditorBrowsableState.Never)> _
    <XmlElement("minus1_unfulfilled_count")> _
        Public _Minus1UnfulfilledCount As String

    ''' <summary>
    ''' </summary>
    ''' <value></value>
    ''' <returns>Integer</returns>
    ''' <remarks></remarks>
    <XmlIgnore()> _
    Public ReadOnly Property Minus1UnfulfilledCount() As Integer
        Get
            If Not String.IsNullOrEmpty(Me._Minus1UnfulfilledCount) Then
                Return CInt(Me._Minus1UnfulfilledCount)
            Else
                Return 0
            End If
        End Get
    End Property


    <EditorBrowsable(EditorBrowsableState.Never)> _
    <XmlElement("minus1_fulfilled_count")> _
        Public _Minus1FulfilledCount As String

    ''' <summary>
    ''' </summary>
    ''' <value></value>
    ''' <returns>Integer</returns>
    ''' <remarks></remarks>
    <XmlIgnore()> _
    Public ReadOnly Property Minus1FulfilledCount() As Integer
        Get
            If Not String.IsNullOrEmpty(Me._Minus1FulfilledCount) Then
                Return CInt(Me._Minus1FulfilledCount)
            Else
                Return 0
            End If
        End Get
    End Property


    <EditorBrowsable(EditorBrowsableState.Never)> _
    <XmlElement("plus1_unfulfilled_count")> _
        Public _Plus1UnfulfilledCount As String

    ''' <summary>
    ''' </summary>
    ''' <value></value>
    ''' <returns>Integer</returns>
    ''' <remarks></remarks>
    <XmlIgnore()> _
    Public ReadOnly Property Plus1UnfulfilledCount() As Integer
        Get
            If Not String.IsNullOrEmpty(Me._Plus1UnfulfilledCount) Then
                Return CInt(Me._Plus1UnfulfilledCount)
            Else
                Return 0
            End If
        End Get
    End Property


    <EditorBrowsable(EditorBrowsableState.Never)> _
    <XmlElement("plus1_fulfilled_count")> _
        Public _Plus1FulfilledCount As String

    ''' <summary>
    ''' </summary>
    ''' <value></value>
    ''' <returns>Integer</returns>
    ''' <remarks></remarks>
    <XmlIgnore()> _
    Public ReadOnly Property Plus1FulfilledCount() As Integer
        Get
            If Not String.IsNullOrEmpty(Me._Plus1FulfilledCount) Then
                Return CInt(Me._Plus1FulfilledCount)
            Else
                Return 0
            End If
        End Get
    End Property


    <EditorBrowsable(EditorBrowsableState.Never)> _
    <XmlElement("plus2_unfulfilled_count")> _
        Public _Plus2UnfulfilledCount As String

    ''' <summary>
    ''' </summary>
    ''' <value></value>
    ''' <returns>Integer</returns>
    ''' <remarks></remarks>
    <XmlIgnore()> _
    Public ReadOnly Property Plus2UnfulfilledCount() As Integer
        Get
            If Not String.IsNullOrEmpty(Me._Plus2UnfulfilledCount) Then
                Return CInt(Me._Plus2UnfulfilledCount)
            Else
                Return 0
            End If
        End Get
    End Property


    <EditorBrowsable(EditorBrowsableState.Never)> _
    <XmlElement("plus2_fulfilled_count")> _
        Public _Plus2FulfilledCount As String

    ''' <summary>
    ''' </summary>
    ''' <value></value>
    ''' <returns>Integer</returns>
    ''' <remarks></remarks>
    <XmlIgnore()> _
    Public ReadOnly Property Plus2FulfilledCount() As Integer
        Get
            If Not String.IsNullOrEmpty(Me._Plus2FulfilledCount) Then
                Return CInt(Me._Plus2FulfilledCount)
            Else
                Return 0
            End If
        End Get
    End Property

End Class